Skip to content

fix: widen requestedSchema type to accept Zod toJSONSchema output#1694

Closed
travisbreaks wants to merge 1 commit intomodelcontextprotocol:mainfrom
travisbreaks:fix/zod-json-schema-type-compat
Closed

fix: widen requestedSchema type to accept Zod toJSONSchema output#1694
travisbreaks wants to merge 1 commit intomodelcontextprotocol:mainfrom
travisbreaks:fix/zod-json-schema-type-compat

Conversation

@travisbreaks
Copy link

Summary

Fixes #1362.

Zod v4's .toJSONSchema() returns standard JSON Schema fields ($schema, additionalProperties) that the requestedSchema type in ElicitRequestFormParams rejected at the TypeScript level, requiring users to cast with as unknown as ....

Changes:

  • Added additionalProperties?: boolean and [key: string]: unknown index signature to the requestedSchema type in spec.types.ts
  • Added additionalProperties: z.boolean().optional() and .passthrough() to the Zod schema in types.ts so extra JSON Schema fields survive runtime validation
  • Added regression test verifying Zod's .toJSONSchema() output works with elicitInput()

All 388 existing tests pass. Typecheck and lint clean.

Test plan

  • Verify z.object({...}).toJSONSchema() passes type check when assigned to requestedSchema
  • Verify runtime validation accepts standard JSON Schema fields
  • Verify existing elicitation behavior is unchanged

…tput

Zod v4's `.toJSONSchema()` produces standard JSON Schema that includes
`$schema` and `additionalProperties` fields. The `requestedSchema` type
in `ElicitRequestFormParams` rejected these valid fields at the TypeScript
level, even though they work correctly at runtime.

Changes:
- Add `additionalProperties?: boolean` to requestedSchema in spec.types.ts
- Add index signature `[key: string]: unknown` for forward compatibility
  with other standard JSON Schema fields
- Add `.passthrough()` to the Zod schema in types.ts so extra fields
  survive runtime validation
- Add regression test verifying Zod toJSONSchema() output works with
  elicitInput()

Closes modelcontextprotocol#1362
@travisbreaks travisbreaks requested a review from a team as a code owner March 17, 2026 04:19
@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2026

⚠️ No Changeset found

Latest commit: 0c8fbdb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 17, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1694

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1694

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1694

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1694

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1694

commit: 0c8fbdb

@felixweinberger
Copy link
Contributor

Thanks for the contribution! Closing in favor of #1768.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TypeScript] Zod's .toJSONSchema() output type incompatible with elicitInput's requestedSchema parameter

2 participants